home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
msn
/
MSNUtil.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
196 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from struct import pack, unpack
from urllib2 import quote, unquote
from base64 import b64encode, b64decode
from string import zfill
from util import get_func_name, get_func, pythonize, to_storage, Timer, default_timer, fmt_to_dict, fuzzydecode
from logging import getLogger
log = getLogger('msn.util')
from mail.passport import make_auth_envelope
msgtypes = {
'text/x-msmsgsprofile': 'profile',
'text/x-msmsgsinitialmdatanotification': 'notification',
'text/x-msmsgscontrol': 'control',
'text/plain': 'plain',
'text/x-msmsgsinitialemailnotification': 'init_email',
'text/x-msmsgsemailnotification': 'new_email',
'text/x-msmsgsinvite': 'invite',
'text/x-msnmsgr-datacast': 'datacast',
'application/x-msnmsgrp2p': 'p2p',
'text/x-clientcaps': 'caps',
'text/x-msmsgsoimnotification': 'oims' }
def utf8_encode(str):
return unicode(str, 'utf-8')
def utf8_decode(str):
return str.encode('utf-8')
def url_encode(str):
return quote(str)
def url_decode(str):
return unquote(str)
def base64_encode(s):
return s.encode('base64').replace('\n', '')
def base64_decode(s):
return s.decode('base64')
def utf16_encode(str):
try:
return unicode(str, 'utf-16')
except TypeError:
if isinstance(str, unicode):
return str.encode('utf-16')
else:
return fuzzydecode(s, 'utf-8').encode('utf-16')
except:
isinstance(str, unicode)
def utf16_decode(str):
return str.decode('utf-16')
mime_to_dict = fmt_to_dict(';', '=')
csd_to_dict = fmt_to_dict(',', '=')
def mime_to_storage(str):
info = mime_to_dict(str)
for k in info.keys():
info[pythonize(k)] = info[k]
return to_storage(info)
def csd_to_storage(str):
info = csd_to_dict(str)
for k in info.keys():
info[pythonize(k)] = info.pop(k)
return to_storage(info)
def gen_msg_payload(obj, socket, trid, msg, src_account, src_display, *params):
type = msg.get('Content-Type', None)
if type:
type = type.split(';')[0]
if type not in msgtypes:
log.critical("Can't handle type %s", type)
return None
func = get_func(obj, get_func_name(2) + '_%s' % msgtypes[type])
if func:
func(socket, msg, src_account, src_display, *params)
def dict_to_mime_header(d):
hdr = [
'MIME-Version: 1.0']
ctype = 'Content-Type'
ctype_val = d.pop(ctype, 'text/plain; charset=UTF-8')
hdr.append('%s: %s' % (ctype, ctype_val))
for k, v in d.items():
if isinstance(v, dict):
v = dict_to_mime_val(v)
hdr.append('%s: %s' % (k, v))
return '\r\n'.join(hdr) + '\r\n'
def dict_to_mime_val(d):
s = []
for k, v in d.items():
None(s.append if k else '' + '%s' % v)
return '; '.join(s)
def bgr_to_rgb(c):
s = '000000' + c[-6:]
(b, g, r) = [ a + b for a, b in zip(s[::2], s[1::2]) ]
return r + g + b
def rgb_to_bgr(s):
(r, g, b) = [ a + b for a, b in zip(s[::2], s[1::2]) ]
s = b + g + r
while s.startswith('0'):
s = s[1:]
continue
[]
return s
class FuncProducer(object):
def __init__(self, f):
object.__init__(self)
self.f = f
def more(self):
try:
v = self.f()
except:
v = None
finally:
return v
def q_untilready(func):
def wrapper(self, *a, **k):
if self.state == 'ready' and self.session_id == None and self.type == 'sb':
print 'ERROR STATE DETECTED: CALLING DISCONNECT', self
self.disconnect()
print 'in quntilready -- %r' % self
if self.state != 'ready':
self._q.append((func, (self,) + a, k))
if self.state == 'disconnected':
self.connect()
elif self.state != 'calling':
self.invite(self.buddy)
else:
return func(self, *a, **k)
return wrapper
import functools
def dispatch(f):
def wrapper(self, *a, **k):
print 'DISPATCH type:', self.type
fname = '_%s_%s' % (f.func_name.lstrip('_'), self.type)
if f(self, *a, **k):
print 'dispatch: calling %s' % fname
return getattr(self, fname)(*a, **k)
else:
print 'dispatch: not calling %s' % fname
return False
wrapper = (functools.wraps(f),)(wrapper)
return wrapper